package com.faiz.algorithm;


public class ThrowEggs {

    /**  优化方向，可以避免一下重复调用
     * @param n 楼层层数
     * @param m 鸡蛋数量
     * @return
     */
    public static int throwEggs(int n, int m) {
        if (n == 0) {
            return 0;
        }
        //这里需要n >= 1
        if (m == 1) {
            return n;
        }
        int res = 100;
        for (int i = 1; i <= n; i++) {
            res = Math.min(res, Math.max(throwEggs(i - 1, m - 1), throwEggs(n - i, m)) + 1);
        }
        return res;
    }

    public static void main(String[] args) {
        System.out.println(throwEggs(30, 2));
    }
}
